<%-- 
    Document   : EditRoom
    Created on : Apr 3, 2014, 5:00:08 PM
    Author     : mishra
--%>
<%@page import="java.util.Iterator"%>
<%@page import="Hostel.HostelBean"%>
<%@page import="java.util.Vector"%>

<!DOCTYPE html>
<%
    try {
        if (session.getAttribute("uid") != null) {
            if (session.getAttribute("Room").toString().equals("1")) {
%>
<html>
    <head>
        <title>Ramgovind Automated System</title>

        <link rel="stylesheet" href="/RIT/css/bootstrap.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap-responsive.css">
        <link rel="stylesheet" href="/RIT/css/jquery.fancybox.css">
        <link rel="stylesheet" href="/RIT/css/style.css">
        <link rel="stylesheet" href="/RIT/css/iconfont.css">
        <link rel="stylesheet" href="/RIT/css/bootstrap.datepicker.css">
        <script src="../../ajax/ajax.js"></script>
        <script>
            function getEditRoom(){
                var NoofBeds= document.getElementById('noOfBed').value;
                var hosteid= document.getElementById('hosid').value;
                var roon= document.getElementById('roomN').value;
                var feess= document.getElementById('fees').value;
                var av= document.getElementById('avi').value;
                var xmlhttp; 
                if (window.XMLHttpRequest)
                {
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                    
                xmlhttp.onreadystatechange=function()
                { 
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        document.getElementById('rm').innerHTML = xmlhttp.responseText;  
                    }
                }
                xmlhttp.open("POST","/RIT/EditRoom?noofBeds="+NoofBeds+"&hid="+hosteid+"&roomNo="+roon+"&Rent="+feess+"&Availibi="+av,true);
                xmlhttp.send();
            }
            function getEnable(id){
                document.getElementById(id).readOnly=false;
            }
            function getEnableRent(id){
                var avil=parseInt(document.getElementById('avi').value);
                var noOfBd=parseInt(document.getElementById('nofbed').value);
                if(avil==noOfBd){
                document.getElementById(id).readOnly=false;
                }else{
                    document.getElementById(id).readOnly=true;
                }
            }
            function deleteBedsconfirm(id){
                var val=id.split("/");
                document.getElementById('myModal').className='modal';
                var i=document.getElementById('delbed'+val[1]).value;
                document.getElementById('delthis').value = i;
                
            }
            function deleteBed()
            {
                
                var bedna=document.getElementById('delthis').value.split("--");
                if(bedna[2]=="0")
                {
                var xmlhttp; 
                if (window.XMLHttpRequest)
                {
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                { 
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        var temp=xmlhttp.responseText;
                        if(temp==1)
                        {
                            var table = document.getElementById(bedna[0]);
                            for(var j=2;j>=0;j--)
                            {
                                table.deleteCell(j);
                                document.getElementById('myModal').className='modal hide';
                            } 
                            document.getElementById('noOfBed').value=parseInt(document.getElementById('noOfBed').value)-1
                        }
                        else
                        {
                            alert("This Data is Used at Some Other Place");
                        }
                    }
                }
                xmlhttp.open("POST","/RIT/DeleteBeds?bno="+bedna[0]+"&roomno="+bedna[1],true);
                xmlhttp.send();
            }else{
                alert("Bed Alloted and can't be deleted");
                document.getElementById('myModal').className='modal hide';
            }
            }
            
            function checkBed(max,min)
            {   
                var ma=parseInt(max);
                var mi=parseInt(min);
                if(mi>ma)
                {
                alert("You can't Enter Less then Available-->"+mi+".Beds");
                }
            }
            function Cancel(){
                document.getElementById('myModal').className='modal hide';
            }
           /* function addBeds()
            {
                var hid=document.getElementById('hosid').value;
                var room=document.getElementById('roomN').value;
                var nob=document.getElementById('noOfBed').value;
                var fees=document.getElementById('fees').value;
                var xmlhttp; 
                if (window.XMLHttpRequest)
                {
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                { 
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        if(xmlhttp.responseText=="0"){
                            
                        }else{
                            document.getElementById('noOfBed').value=nob;
                            document.reload();
                        }
                    }
                }
                xmlhttp.open("POST","/RIT/AddBed?hid="+hid+"&room="+room+"&nob="+nob+"&fees="+fees,true);
                xmlhttp.send();
            }*/
        </script>

    </head>
    <body onload="getEditRoom()">
        <%@include file="/topheader.html" %>
        <%@include file="/settingheader.html" %>
        <div class="main">
            <div class="container-fluid">
                <%@include file="/Settings/dbsidenav.html" %>
                <div class="content">

                    <div class="row-fluid">
                        <div class="span12">
                            <div class="box">
                                <div class="modal hide" id="myModal">
                                <div class="modal-header">
                                    <button type="button" class="close" onclick="document.getElementById('myModal').className='modal hide'"><img src="/RIT/img/mclose.png"></button>
                                    <h3 style=" color: red;">Warning...</h3>
                                </div>
                                <div class="modal-body">
                                    <p>Are you sure to delete?</p>
                                </div>
                                <div class="modal-footer">
                                    <input type="hidden" value="" id="delthis">
                                    <a href="#" class="btn btn-primary" onclick="deleteBed()">Ok </a>
                                    <a href="#" class="btn btn-success" onclick="Cancel()">Cancel</a>
                                </div>
                            </div>
                                <div class="box-head">
                                    <h3>Room Information</h3>
                                    <a onclick="window.history.back()">
                                        <button style="float: right" class="btn btn-success">View Room</button>
                                    </a>
                                </div>

                                <form action="/RIT/AddBed" method="post" class='validate form-horizontal'>
                                    <div class="box-content">
                                        <!---Form Start....-->
                                        <legend>
                                            Hostel Details
                                        </legend>
                                        <div id="lside" style="float: left; margin-top: 10px; width: 48%;">
                                            <input type="hidden" id="hosid" name="hosid" value="<%=request.getParameter("hostelid")%>">
                                            <input type="hidden" id="roomN" name="roomN" value="<%=request.getParameter("roomno")%>">
                                            <input type="hidden" id="fees" name="fees" value="<%=request.getParameter("rent")%>">
                                            <input type="hidden" id="avi" name="avi" value="<%=request.getParameter("avai")%>">
                                            <input type="hidden" id="nofbed" name="nofbed" value="<%=request.getParameter("noofbeds")%>">
                                            <div class="control-group">
                                                <label for="hname" class="control-label">Hostel Name<span style="color:red">*</span></label>
                                                <div class="controls">
                                                    <select name="hname" id="hname" readonly onchange="checkRoomAllot(this.value)">
                                                        <option value="<%=request.getParameter("hostelname")%>"><%=request.getParameter("hostelname")%></option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label for="roomNo" class="control-label">Room Number</label>
                                                <div class="controls">
                                                    <div class="span3">
                                                        <input type="text" name="roomNo" id="roomNo" readonly onblur="getRooms(this.value)" value="<%=request.getParameter("roomno")%>">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div id="rside" style="float: left; margin-right: 0px; margin-top: 10px">
                                            <div class="control-group">
                                                <label for="rent" class="control-label">Additional Room Rent</label>
                                                <div class="controls">
                                                        <input type="text" name="roomrent" id="roomrent" readonly value="<%=request.getParameter("rent")%>">
                                                        <a href="#"><img alt="edit" title="Edit" class="ico-prev" id="editrent" name="editrent"  onclick="getEnableRent('roomrent')" src="/RIT/img/icons/essen/16/pencil.png"></a>
                                                </div>
                                            </div>
                                            <div class="control-group">
                                                <label for="noOfBed" class="control-label">Number of Beds</label>
                                                <div class="controls">
                                                    <input type="text" name="noOfBed" id="noOfBed" class="number" readonly value="<%=request.getParameter("noofbeds")%>" onblur="checkBed(this.value,document.getElementById('nofbed').value)">
                                                    <a href="#"><img alt="edit" title="Edit" class="ico-prev" id="editbed" name="editbed"  onclick="getEnable('noOfBed')" src="/RIT/img/icons/essen/16/pencil.png"></a>
                                                </div>
                                            </div>
                                        </div>
                                     <div id="lside" style="float: left; margin-top: 10px; width: 48%;">
                                    <div class="controls-group">
                                        <div class="controls">
                                        <input type="submit" value="submit" name="sub" id="sub" class='btn btn-primary'>
                                        </div>
                                    </div>
                                     </div>
                                   </div>
                                        <div id="rm" style="margin-top: 30px;">

                                        </div>
                                        <!---Form Ends....-->
                                    
                                </form>
                            </div>
                        </div>
                    </div>

                </div>	
            </div>
        </div>

        <script src="/RIT/js/jquery.js"></script>
        <script src="/RIT/js/less.js"></script>
        <script src="/RIT/js/bootstrap.min.js"></script>
        <script src="/RIT/js/jquery.uniform.min.js"></script>
        <script src="/RIT/js/bootstrap.timepicker.js"></script>
        <script src="/RIT/js/bootstrap.datepicker.js"></script>
        <script src="/RIT/js/chosen.jquery.min.js"></script>
        <script src="/RIT/js/jquery.fancybox.js"></script>
        <script src="/RIT/js/plupload/plupload.full.js"></script>
        <script src="/RIT/js/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
        <script src="/RIT/js/jquery.cleditor.min.js"></script>
        <script src="/RIT/js/jquery.inputmask.min.js"></script>
        <script src="/RIT/js/jquery.tagsinput.min.js"></script>
        <script src="/RIT/js/jquery.mousewheel.js"></script>
        <script src="/RIT/js/jquery.textareaCounter.plugin.js"></script>
        <script src="/RIT/js/ui.spinner.js"></script>
        <script src="/RIT/js/jquery.jgrowl_minimized.js"></script>
        <script src="/RIT/js/jquery.form.js"></script>
        <script src="/RIT/js/jquery.validate.min.js"></script>
        <script src="/RIT/js/bbq.js"></script>
        <script src="/RIT/js/jquery-ui-1.8.22.custom.min.js"></script>
        <script src="/RIT/js/jquery.form.wizard-min.js"></script>
        <script src="/RIT/js/jquery.cookie.js"></script>
        <script src="/RIT/js/jquery.metadata.js"></script>
        <script src="/RIT/js/custom.js"></script><script src="/RIT/js/demo.js"></script>
        <script src="/RIT/js/iconfont.js"></script>
    </body>
</html>

<%} else {
%>
<script type="text/javascript">
    alert("You Are Not Authorised");
    window.history.back();
</script>
<%             }
        } else {
            request.setAttribute("msg", "You Are Not Authorised! Please Contact to System Administrator!");
            request.setAttribute("value", "0");
            getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
        }
    } catch (Exception e) {
        request.setAttribute("msg", "Please Contact to System Administrator!");
        request.setAttribute("value", "0");
        getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
    }
%>
